package c.francis.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import c.francis.service.impl.MemberServiceImpl;
import c.francis.utils.CookieUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import c.francis.pojo.Category;
import c.francis.pojo.Category_Room_SubDtl;
import c.francis.pojo.Member;
import c.francis.service.impl.CategoryServiceImpl;
import c.francis.service.impl.Category_Room_SubscriptionServiceImpl;
@Controller
public class Category_Room_DtlController {
	
	@Autowired
	private Category_Room_SubscriptionServiceImpl category_Room_SubscriptionServiceImpl;

//	@Qualifier("categoryServiceImpl")
	@Autowired
	private CategoryServiceImpl categoryService;

	@Autowired
	private MemberServiceImpl	memberService;
	
	
	@RequestMapping("queryAllSubCateR")
	public ModelAndView getAllCategoSub(HttpServletRequest request,@RequestParam("sid")int sid) {
		ModelAndView modelAndView = new ModelAndView();


//		HttpSession session = request.getSession();
//		Member member = (Member)session.getAttribute("member");

		String ticket = CookieUtils.getValue(request, "ticket");
		Member member = memberService.findMemberByTicket(ticket);

		List<Category_Room_SubDtl> category_Room_SubDtls = category_Room_SubscriptionServiceImpl.selectAllSubRoom(member.getId(),sid);
		modelAndView.addObject("category_Room_SubDtls", category_Room_SubDtls);
		modelAndView.addObject("sid", sid);
		modelAndView.setViewName("subscription_dtl");
		return modelAndView;
	}
	
	
	
	@RequestMapping("addBooks")
	public ModelAndView queryAddSubdtl(@RequestParam("sid")int sid) {
		ModelAndView modelAndView = new ModelAndView();
		List<Category> categories = categoryService.queryAllCategories();
		
		modelAndView.addObject("categories", categories);
		modelAndView.addObject("sid", sid);
		
		System.out.println(sid);
		
		modelAndView.setViewName("addbooks");
		return modelAndView;
	}
	
	
	//����mid��ѯ����״̬c����ʷ����
	@RequestMapping("queryhistory")
	public ModelAndView queryhistory(/**HttpSession session,*/HttpServletRequest	request) {
		ModelAndView modelAndView = new ModelAndView();

		//Member member = (Member) session.getAttribute("member");

		String ticket = CookieUtils.getValue(request, "ticket");
		Member member = memberService.findMemberByTicket(ticket);

		List<Category_Room_SubDtl> historysubs = category_Room_SubscriptionServiceImpl.queryHistorySub(member.getId(), "c");
		modelAndView.addObject("historysubs", historysubs);
		modelAndView.setViewName("historysubs");
		return modelAndView;
	}
	
	//��ת��������ѯ�������
	@RequestMapping("queryMuti")
	public ModelAndView queryMuti() {
		ModelAndView modelAndView = new ModelAndView();
		List<Category_Room_SubDtl> category_Room_SubDtls =  category_Room_SubscriptionServiceImpl.queryMutiSub("", "m");
		modelAndView.setViewName("admin_managesub");
		modelAndView.addObject("category_Room_SubDtls", category_Room_SubDtls);
		return modelAndView;
	}
	
	
	@RequestMapping("querybtnmuti")
	public @ResponseBody List<Category_Room_SubDtl> querybtnmuti(String status,String phone) {
		List<Category_Room_SubDtl> category_Room_SubDtls =  category_Room_SubscriptionServiceImpl.queryMutiSub(phone, status);
		return category_Room_SubDtls;
	}
	
	
	
	
	
	
}
